class MyStack {
public:
    MyStack() {
        buffer_ = new int[buffer_size_];
        memset((void *)buffer_, 0, buffer_size_ * sizeof(int));
    }
    
    void push(int x) {
        if (count_ >= buffer_size_ - 1) {
            int *temp = new int[buffer_size_ * 2];
            memcpy((void *)temp, buffer_, buffer_size_ * sizeof(int));
            delete[] buffer_;
            buffer_ = temp;
            buffer_size_ = buffer_size_ * 2;
        }
        buffer_[count_] = x;
        count_++;
    }
    
    int pop() {
        int ret;
        if (count_ > 0) {
            ret = buffer_[count_ - 1];
            count_--;
            return ret;
        } else {
            return 0;
        }

    }
    
    int top() {
        if (count_ > 0)
            return buffer_[count_ - 1];
        else 
            return 0;
    }
    
    bool empty() {
        return count_ > 0 ? false : true;
    }
private:
    int count_ = 0;
    int *buffer_ = nullptr;
    int buffer_size_ = 64;
};